"Leave it marked, but let you navigate to it," & CRLF & TAB &\
"Or pack the database and delete the record." \
with "Unmark" or "Leave Marked" or "Pack and Delete"
conditions
when it is "Unmark"
get setDBRecordDeleted(0) -- undelete
get goToDBRecord(value)
when it is "Leave Marked"
-- remember old value
set NavToDel to getDBNavigateToDeleted()
-- get set and go
get setDBNavigateToDeleted(1)
get goToDBRecord(value)
-- reset old value
get setDBNavigateToDeleted(NavToDel)
when it is "Pack and Delete"
sysCursor = 4
get packDBFile()
if it < 1
request getDBErrorString(it)
else
-- some default behavior, nothing but something to do
get firstDBKey()
end if
end conditions
else
request getDBErrorString(it)
end if
end if
end currentRecord
-- We need a corresponding "to get" handler, but this is very simple
to get currentRecord
get getDBRecordNumber()
if it < 1
request getDBErrorString(it)
end if
-- calling handler would need to check this value to see if
-- an error has occured.
return it
end currentRecord
}
SCRIPT "Set the value of a field in dBIII"
BEHAVIOR "An example for setting the value of a field in a .dbf file"
CATEGORIES dBaseIII
{
-- Simple wrapper for setDBFieldValue,
-- A call to it might look like:
-- "set fieldValue(firstName) to "Jimmy"", or
-- "fieldValue(lastName) = "Carter"".
-- It sets the field in the current record.
to set fieldValue fieldName to value
get setDBFieldValue(fieldName, value)
if it < 0
request getDBErrorString(it)
end if
end fieldValue
}
SCRIPT "Get the value of a DBIII field"
BEHAVIOR "An example for getting the value of a field in a .dbf file"
CATEGORIES dBaseIII
{
-- Simple wrapper for getDBFieldValue
-- typically fieldName would be passed in a to get handler like:
-- "get fieldValue("lastName")", which would return a last name.
to get fieldValue fieldName
clear sysError
get getDBFieldValue(fieldName)
if sysError is not null
request getDBErrorString(syserror)
else
return it
end if
return null
end fieldValue
}
SCRIPT "Create a new DBIII record"
BEHAVIOR "An example for creating a new record in a database"
CATEGORIES dBaseIII
{
-- Creates a new (and empty) record.
to handle newDBRecord
-- We create a new record by writing past the end of the database.
get writeDBRecord(getDBRecordCount() + 1)
if it < 0
request getDBErrorString(it)
end if
end newDBRecord
}
SCRIPT "Write to a DBIII database"
BEHAVIOR "An example for writing a record out to a .dbf file."
CATEGORIES dBaseIII
{
-- Simple wrapper for writeDBRecord. This is where the dBase record
-- is actually written out. The handler expects you to pass the
-- record number of the record that is being written, so this would
-- be called like this: "send writeDB getDBRecordNumber()", or with any
-- other value that would evaluate to a record number.
to handle writeDB rNumber
get writeDBRecord(rNumber)
if it < 0
request getDBErrorString(it)
end if
end writeDB
}
SCRIPT "Delete a dBIII record"
BEHAVIOR "An example for marking and deleting a record from a .dbf file."
CATEGORIES dBaseIII
{
-- Simple wrapper for setDBRecordDeleted. Note also we pack the dBase here,
-- there's no recovery for a deleted file.
to handle deleteRecord
-- This marks the current record as "deleted"
get setDBRecordDeleted(1)
if it < 0
request getDBErrorString(it)
end if
-- You may not want the next line if you want to be able to
-- recover from this operation. It is possible to undelete a marked record,
-- but not after you have packed the database.
-- Note that this refers to a ToolBook handler, not a DLL function.
send packDatabase
end deleteRecord
}
SCRIPT "Pack a dBIII File"
BEHAVIOR "An example for packing a dBase file and any associated, open indexes."
CATEGORIES dBaseIII
{
-- Simple wrapper for packDBFile
to handle packDatabase
sysCursor = 4
-- Operates on the current dBase
get packDBFile()
if it < 1
request getDBErrorString(it)
end if
sysCursor = default
end packDatabase
}
SCRIPT "Turn a ToolBook field into a dBase field"
BEHAVIOR "An appropriately named field can quickly become a window on a DBIII database by placing these handlers in the script of a field, and broadcasting the appropriate messages."
CATEGORIES dBaseIII
{
-- Get and set data for and from these fields
notifyBefore updateDisplay
-- this call the "to get fieldValue" function
-- found under the name of "Get the value of a DBIII field" in tb40.ats
my text = fieldValue(my name) of this book
end updateDisplay
notifyBefore updateDB
-- this call the "to set fieldValue" handler
-- found under the name of "Set the value of a field in DBIII " in tb40.ats